<template>
  <a-table
    ref="table"
    size="middle"
    :scroll="{x:true}"
    bordered
    rowKey="orgId"
    :columns="columns"
    :dataSource="dataSource"
    :pagination="ipagination"
    :loading="loading"
    class="j-table-force-nowrap"
    @change="handleTableChange">
  </a-table>
</template>

<script>
import { getAction } from '@api/manage'

export default {
  name: 'CoreSummaryForSchool',
  props: {
    date:{
      type: String,
      required: false
    },
    scoreType:{
      type: Number,
      required: true
    }
  },
  watch:{
    date(){
      this.loadData();
    },
  },
  data(){
    return {
      columns:[
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },

        {
          title:'部门',
          align:"center",
          dataIndex: 'orgName'
        },
        {
          title:'教学建设',
          align:"center",
          dataIndex: 'teachingBuild',
          sorter: (a, b) => a.teachingBuild - b.teachingBuild,
        },
        {
          title:'学生大赛',
          align:"center",
          dataIndex: 'studentMatch',
          sorter: (a, b) => a.studentMatch - b.studentMatch,
        },
        {
          title:'科学研究与社会服务',
          align:"center",
          dataIndex: 'research',
          sorter: (a, b) => a.research - b.research,
        },
        {
          title:'基层党建与学生管理',
          align:"center",
          dataIndex: 'studentManage',
          sorter: (a, b) => a.studentManage - b.studentManage,
        },
        {
          title:'总分',
          align:"center",
          dataIndex: 'totalScore',
          sorter: (a, b) => a.totalScore - b.totalScore,
        }


      ],
      ipagination: {
        pageSize: 15
      },
      loading:false,
      dataSource:[],
      url:{
        list: 'statistics/coreSummary/listSummaryForSchool'
      }
    }
  },
  methods:{
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      this.loadData();
    },
    loadData(){
      if(!this.url.list){
        this.$message.error("请设置url.list属性!")
        return
      }

      let params = {date:this.date}
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.records||res.result;
          if(res.result.total)
          {
            this.ipagination.total = res.result.total;
          }else{
            this.ipagination.total = 0;
          }
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    }
  },
  created() {
    this.loadData();
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>